package semant.second_pass;

import java.util.Enumeration;

import semant.Env;
import symbol.ClassInfo;
import symbol.MethodInfo;
import symbol.Symbol;
import syntaxtree.ClassDecl;
import syntaxtree.ClassDeclExtends;
import syntaxtree.ClassDeclSimple;
import syntaxtree.MethodDecl;
import syntaxtree.Statement;
import syntaxtree.VisitorAdapter;
import util.List;

public class ClassDeclHandler extends VisitorAdapter {

	private Env env;
	
	public ClassDeclHandler(Env e)
	{
		env = e;
	}
	
	public static void secondPass(Env e, ClassDecl cl) {
		ClassDeclHandler h = new ClassDeclHandler(e);
		cl.accept(h);
	}

	@Override
	public void visit(ClassDeclSimple node) {
		Symbol cname = Symbol.symbol(node.name.s);
		ClassInfo ci = env.classes.get(cname);
		
		for (List<MethodDecl> v = node.methodList; v != null; v = v.tail) {
            MethodHandler.secondPass(env, ci, v.head);
        }
	}

	@Override
	public void visit(ClassDeclExtends node) {
		Symbol cname = Symbol.symbol(node.name.s);
		ClassInfo ci = env.classes.get(cname);
		
		for (List<MethodDecl> v = node.methodList; v != null; v = v.tail) {
            MethodHandler.secondPass(env, ci, v.head);
        }
	}
	
	

}
